import pandas as pd

from getdata.StockHistory import StockHistoryInterface, StockHistory_by_Akshare
from getdata.StockTick import StockTickInterface, StockTick_by_Akshare

import akshare as ak
class GetData:
    codes=['600036','002594','300006','000905','002607']
    def get_save(self, stockTickInterface:StockHistoryInterface):
        for item in self.codes:
            print(item)
            df=stockTickInterface.get(item,'20210101','20230701')
            print(df)
            #save df to csv
            df.to_csv('./data/'+item+'.csv')
    def get_index_data(self):
        print('get index data')
        stock_zh_index_daily_df = ak.stock_zh_index_daily(symbol="sh000001")
        print(stock_zh_index_daily_df)
        # 确保日期列是日期格式
        stock_zh_index_daily_df['date'] = pd.to_datetime(stock_zh_index_daily_df['date'])

        # 选取2021年1月1日至2023年6月30日期间的数据
        start_date = '2021-01-01'
        end_date = '2023-06-30'
        filtered_df = stock_zh_index_daily_df[
            (stock_zh_index_daily_df['date'] >= start_date) & (stock_zh_index_daily_df['date'] <= end_date)]
        print(filtered_df)
        filtered_df.to_csv('./data/sh000001.csv')
if __name__ == '__main__':
    gd=GetData()
    # gd.get_save(StockHistory_by_Akshare())
    gd.get_index_data()